#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
void printpending(sigset_t &pending){
    for(int size = 31; size >= 1; size--)
    {
        std::cout << sigismember(&pending, size);
    }
    std::cout << std::endl;
}
void hander(int node){
    std::cout << "信号被递达！" << std::endl;
    sigset_t pending;
    sigpending(&pending);
    printpending(pending);
    std::cout << "sigset_t over!!!" << std::endl;
}
int main()
{
    signal(2, hander);
    sigset_t block_sig, old_sig;
    sigemptyset(&block_sig);
    sigemptyset(&old_sig);
    sigaddset(&block_sig, 2);
    sigprocmask(SIG_BLOCK, &block_sig, &old_sig);
    int cnt = 15;
    while(true) 
    {
        sigset_t pending;
        sigpending(&pending);
        printpending(pending);
        cnt--;
        if(cnt == 0)
        {
            sigset_t New;
            sigemptyset(&New);
            sigaddset(&New, 2);
            sigprocmask(SIG_UNBLOCK, &New, &block_sig);
        }
        
        sleep(1);
    }
}